import { defineStore } from 'pinia'
import {
  reqGetCategory1,
  reqGetCategory2,
  reqGetCategory3
} from '@/api/product/attr/index'
import type { CategoryState } from './types/type'

const useCategoryStore = defineStore('Category', {
  state: (): CategoryState => {
    return {
      category1Id: '',
      category1List: [],
      category2Id: '',
      category2List: [],
      category3Id: '',
      category3List: []
    }
  },
  actions: {
    async getCategory1() {
      const result = await reqGetCategory1()
      this.category1List = result.data
    },
    async getCategory2() {
      const result = await reqGetCategory2(this.category1Id)
      this.category2List = result.data
    },
    async getCategory3() {
      const result = await reqGetCategory3(this.category2Id)
      this.category3List = result.data
    }
  }
})
export default useCategoryStore
